﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WindowsFormsApplication1.BLL;
using Millionaire;

namespace WindowsFormsApplication1
{
    public partial class FrmCauHoi : Form
    {
        CauHoiBLL chBLL;
        LuaTuoiBLL ltBLL;
        LinhVucBLL lvBLL;
        OpenFileDialog ofd;
        public FrmCauHoi()
        {
            InitializeComponent();
            chBLL = new CauHoiBLL();
            lvBLL = new LinhVucBLL();
            ltBLL = new LuaTuoiBLL();
            cbLT.DisplayMember = "TenLuaTuoi";
            cbLT.ValueMember = "MaLuaTuoi";
            cbLT.DataSource = ltBLL.GetAll();
            cbLV.DisplayMember = "TenLinhVuc";
            cbLV.ValueMember = "MaLinhVuc";
            cbLV.DataSource = lvBLL.GetAll();
        }

        private void btnThem_Click(object sender, EventArgs e)
        {
            
           
            CauHoi ch = new CauHoi()
            {
                CauA = txtCauA.Text,
                CauB = txtCauB.Text,
                CauC = txtCauC.Text,
                CauD = txtCauD.Text,
                CauHoi1 = txtCauHoi.Text,
                DapAn = cbDapAn.SelectedItem.ToString(),
                MaLinhVuc = (int)cbLV.SelectedValue,
                MaLuaTuoi = (int)cbLT.SelectedValue,
                MucDo = (int)numericUpDown1.Value,
            };
            if (ofd != null)
            {
                ch.CauHoi1 += "#" + ofd.SafeFileName;
            }
          

            chBLL.AddNew(ch);

        }

        private void btnBrowse_Click(object sender, EventArgs e)
        {
            ofd = new OpenFileDialog();
            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                txtPath.Text = ofd.FileName;
               
            }
        }
    }
}
